package com.luying.pojo;

import com.luying.constants.CommonCodeConstants;

import java.util.HashMap;
import java.util.Optional;

public class Result
{
    private Integer code;
    private String msg;
    private Object data;

    public Result() {}

    public Result(Object data)
    {
        this.code = CommonCodeConstants.SUCCESS_CODE;
        this.msg = "success";
        this.data = data;
    }

    public Result(Integer code, String msg, Object data)
    {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result ok(Object data)
    {
        return new Result(data);
    }

    public static Result ok()
    {
        return new Result(Integer.valueOf(10000), "success", Boolean.valueOf(true));
    }

    public static Result error(String msg)
    {
        return new Result(CommonCodeConstants.ERROR_CODE, msg, Boolean.valueOf(false));
    }

    public static Result loginFailure(String msg)
    {
        return new Result(CommonCodeConstants.LOGIN_FAILURE_CODE, msg, Boolean.valueOf(false));
    }

    public static Result certificateInvalidation(String msg)
    {
        return new Result(CommonCodeConstants.CERTIFICATE_INVALIDATION_CODE, msg, Boolean.valueOf(false));
    }

    public static Result certificateInvalidation()
    {
        return new Result(CommonCodeConstants.CERTIFICATE_INVALIDATION_CODE, "����������������������", Boolean.valueOf(false));
    }

    public static Result noPermission(String msg)
    {
        return new Result(CommonCodeConstants.NO_PERMISSION_CODE, msg, Boolean.valueOf(false));
    }

    public static Result noPermission()
    {
        return new Result(CommonCodeConstants.NO_PERMISSION_CODE, "��������", Boolean.valueOf(false));
    }

    public static Result build(Integer code, String msg, Object data)
    {
        return new Result(code, msg, data);
    }

    public Integer getCode()
    {
        return this.code;
    }

    public void setCode(Integer code)
    {
        this.code = code;
    }

    public String getMsg()
    {
        return this.msg;
    }

    public void setMsg(String msg)
    {
        this.msg = msg;
    }

    public Object getData()
    {
        Optional<Object> optional = Optional.ofNullable(this.data);
        Object obj = optional.orElse(new HashMap());
        return obj;
    }

    public void setData(Object data)
    {
        this.data = data;
    }

    public String toString()
    {
        return "Result{code=" + this.code + ", msg='" + this.msg + '\'' + ", data=" + this.data + '}';
    }
}
